package com.atnjupt.servlet;

import com.atnjupt.json.bean.Student;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Wizarder
 * @create 2021-06-28 20:58
 */
public class AjaxServlet extends BaseServlet{

    protected void javaScriptAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Ajax请求");
        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
    protected void jQueryAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQueryAjax==请求");
        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
    protected void jQueryPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQueryPost==请求");
        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
    protected void jQueryGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQueryGet==请求");
        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
    protected void jQueryGetJson(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQueryGetJson==请求");
        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
    protected void jQuerySerialize(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("jQuerySerialize==请求");

        Student student = new Student(1,"路浩");
        Gson gson  = new Gson();
        String studnetJsonString = gson.toJson(student);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(studnetJsonString);
    }
}
